package com.tuozixuan.camel.springredis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RestTemplateConfig {
	
	@Bean
	public RedisTemplate<String, ?> redisTemplate() {
		RedisTemplate<String, String> redisTemplate = new RedisTemplate<String, String>();
		redisTemplate.setConnectionFactory(this.redisConnectionFactory());
		
		redisTemplate.setKeySerializer(new StringRedisSerializer());
        GenericJackson2JsonRedisSerializer jackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
		return redisTemplate;
	}
    
    
    private RedisConnectionFactory redisConnectionFactory() {
    	
    	RedisStandaloneConfiguration redisConfig = new RedisStandaloneConfiguration();
    	redisConfig.setHostName("192.168.80.97");
    	redisConfig.setPort(6379);
    	redisConfig.setPassword("Jkdsaik8248");
    	
    	JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(redisConfig);
        return jedisConnectionFactory;
    }
}
